#Get all packages with the version used for this analysis
renv::restore()
### Syntax Liberal Notions of Democracy in Germany
### APC-Analysis for different aspects of democratic support
#Get all packages with the version used for this analysis
renv::restore()
####Reading the data and loading the packages#####
if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse, haven, mgcv, itsadug, lme4, sjPlot, gridExtra, grid, rlist, texreg, tidymv, psych, GPArotation, rtf, mgcViz, gratia, here)
SYNTAX_DIR <- here::here()
setwd(SYNTAX_DIR)
dat <- haven::read_dta(paste0("data_supportdemocracy_ger.dta"))
####Data Manipulation####
datComplete <- dat %>%
mutate(idea_democracy = round(idea_democracy, 2),
libdem_opposition = round(libdem_opposition, 2),
libdem_freeopinion = round(libdem_freeopinion, 2),
libdem_partyopportunity = round(libdem_partyopportunity, 2),
libdem_criticism = round(libdem_criticism, 2),
libdem_conflict = round(libdem_conflict, 2),
libdem_generalwill = round(libdem_generalwill, 2),
satisfaction_democracy = round(satisfaction_democracy, 2),
period = surveyyear,
birthyear = period - age) %>%
mutate(born_adult = birthyear + 18) %>%
mutate(age_grp = ifelse(age >= 15 & age <20, 1, ifelse(
age >= 20 & age < 30,  2, ifelse(
age >= 30 & age < 40, 3, ifelse(
age >= 40 & age < 50,  4, ifelse(
age >= 50 & age < 60,  5, ifelse(
age >= 60 & age < 70,  6, ifelse(
age >= 70 & age < 80,  7,  8
)
)
)
)
)
)),
age_grp_centered = age_grp - mean(age_grp, na.rm = T),
born_adult_centered = born_adult - mean(born_adult, na.rm = T),
age_grp1 = ifelse(age >= 15 & age < 30, 1,0),     ##Age groups for GAM model
age_grp2 = ifelse(age >= 30 & age < 60, 1, 0),
period.f = as.factor(period))
datComplete <- datComplete %>%
filter(age >= 16 & age <=95) %>%
mutate(age_cohort_five = findInterval(born_adult, c(seq(1910, 2020, by = 5))))  ##cohort groups for rHAPC
#Create subfolders for output
dir.create("plots", showWarnings = FALSE)
dir.create("plots/Appendix", showWarnings = FALSE)
dir.create("tables", showWarnings = FALSE)
###APC-Analysis Diffuse Support
source("02_R_Syntax_diffuse_support_revision.R")
### Syntax Liberal Notions of Democracy in Germany
### APC-Analysis for different aspects of democratic support
#Get all packages with the version used for this analysis
renv::restore()
####Reading the data and loading the packages#####
if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse, haven, mgcv, itsadug, lme4, sjPlot, gridExtra, grid, rlist, texreg, tidymv, psych, GPArotation, rtf, mgcViz, gratia, here)
SYNTAX_DIR <- here::here()
setwd(SYNTAX_DIR)
dat <- haven::read_dta(paste0("data_supportdemocracy_ger.dta"))
####Data Manipulation####
datComplete <- dat %>%
mutate(idea_democracy = round(idea_democracy, 2),
libdem_opposition = round(libdem_opposition, 2),
libdem_freeopinion = round(libdem_freeopinion, 2),
libdem_partyopportunity = round(libdem_partyopportunity, 2),
libdem_criticism = round(libdem_criticism, 2),
libdem_conflict = round(libdem_conflict, 2),
libdem_generalwill = round(libdem_generalwill, 2),
satisfaction_democracy = round(satisfaction_democracy, 2),
period = surveyyear,
birthyear = period - age) %>%
mutate(born_adult = birthyear + 18) %>%
mutate(age_grp = ifelse(age >= 15 & age <20, 1, ifelse(
age >= 20 & age < 30,  2, ifelse(
age >= 30 & age < 40, 3, ifelse(
age >= 40 & age < 50,  4, ifelse(
age >= 50 & age < 60,  5, ifelse(
age >= 60 & age < 70,  6, ifelse(
age >= 70 & age < 80,  7,  8
)
)
)
)
)
)),
age_grp_centered = age_grp - mean(age_grp, na.rm = T),
born_adult_centered = born_adult - mean(born_adult, na.rm = T),
age_grp1 = ifelse(age >= 15 & age < 30, 1,0),     ##Age groups for GAM model
age_grp2 = ifelse(age >= 30 & age < 60, 1, 0),
period.f = as.factor(period))
datComplete <- datComplete %>%
filter(age >= 16 & age <=95) %>%
mutate(age_cohort_five = findInterval(born_adult, c(seq(1910, 2020, by = 5))))  ##cohort groups for rHAPC
#Create subfolders for output
dir.create("plots", showWarnings = FALSE)
dir.create("plots/Appendix", showWarnings = FALSE)
dir.create("tables", showWarnings = FALSE)
###APC-Analysis Diffuse Support
source("02_R_Syntax_diffuse_support_revision.R")
?set.seed
### Syntax Liberal Notions of Democracy in Germany
### APC-Analysis for different aspects of democratic support
#Get all packages with the version used for this analysis
renv::restore()
####Reading the data and loading the packages#####
if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse, haven, mgcv, itsadug, lme4, sjPlot, gridExtra, grid, rlist, texreg, tidymv, psych, GPArotation, rtf, mgcViz, gratia, here)
SYNTAX_DIR <- here::here()
setwd(SYNTAX_DIR)
dat <- haven::read_dta(paste0("data_supportdemocracy_ger.dta"))
####Data Manipulation####
datComplete <- dat %>%
mutate(idea_democracy = round(idea_democracy, 2),
libdem_opposition = round(libdem_opposition, 2),
libdem_freeopinion = round(libdem_freeopinion, 2),
libdem_partyopportunity = round(libdem_partyopportunity, 2),
libdem_criticism = round(libdem_criticism, 2),
libdem_conflict = round(libdem_conflict, 2),
libdem_generalwill = round(libdem_generalwill, 2),
satisfaction_democracy = round(satisfaction_democracy, 2),
period = surveyyear,
birthyear = period - age) %>%
mutate(born_adult = birthyear + 18) %>%
mutate(age_grp = ifelse(age >= 15 & age <20, 1, ifelse(
age >= 20 & age < 30,  2, ifelse(
age >= 30 & age < 40, 3, ifelse(
age >= 40 & age < 50,  4, ifelse(
age >= 50 & age < 60,  5, ifelse(
age >= 60 & age < 70,  6, ifelse(
age >= 70 & age < 80,  7,  8
)
)
)
)
)
)),
age_grp_centered = age_grp - mean(age_grp, na.rm = T),
born_adult_centered = born_adult - mean(born_adult, na.rm = T),
age_grp1 = ifelse(age >= 15 & age < 30, 1,0),     ##Age groups for GAM model
age_grp2 = ifelse(age >= 30 & age < 60, 1, 0),
period.f = as.factor(period))
datComplete <- datComplete %>%
filter(age >= 16 & age <=95) %>%
mutate(age_cohort_five = findInterval(born_adult, c(seq(1910, 2020, by = 5))))  ##cohort groups for rHAPC
#Create subfolders for output
dir.create("plots", showWarnings = FALSE)
dir.create("plots/Appendix", showWarnings = FALSE)
dir.create("tables", showWarnings = FALSE)
###APC-Analysis Diffuse Support
source("02_R_Syntax_diffuse_support_revision.R")
### Syntax Liberal Notions of Democracy in Germany
### APC-Analysis for different aspects of democratic support
#Get all packages with the version used for this analysis
renv::restore()
####Reading the data and loading the packages#####
if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse, haven, mgcv, itsadug, lme4, sjPlot, gridExtra, grid, rlist, texreg, tidymv, psych, GPArotation, rtf, mgcViz, gratia, here)
SYNTAX_DIR <- here::here()
setwd(SYNTAX_DIR)
dat <- haven::read_dta(paste0("data_supportdemocracy_ger.dta"))
####Data Manipulation####
datComplete <- dat %>%
mutate(idea_democracy = round(idea_democracy, 2),
libdem_opposition = round(libdem_opposition, 2),
libdem_freeopinion = round(libdem_freeopinion, 2),
libdem_partyopportunity = round(libdem_partyopportunity, 2),
libdem_criticism = round(libdem_criticism, 2),
libdem_conflict = round(libdem_conflict, 2),
libdem_generalwill = round(libdem_generalwill, 2),
satisfaction_democracy = round(satisfaction_democracy, 2),
period = surveyyear,
birthyear = period - age) %>%
mutate(born_adult = birthyear + 18) %>%
mutate(age_grp = ifelse(age >= 15 & age <20, 1, ifelse(
age >= 20 & age < 30,  2, ifelse(
age >= 30 & age < 40, 3, ifelse(
age >= 40 & age < 50,  4, ifelse(
age >= 50 & age < 60,  5, ifelse(
age >= 60 & age < 70,  6, ifelse(
age >= 70 & age < 80,  7,  8
)
)
)
)
)
)),
age_grp_centered = age_grp - mean(age_grp, na.rm = T),
born_adult_centered = born_adult - mean(born_adult, na.rm = T),
age_grp1 = ifelse(age >= 15 & age < 30, 1,0),     ##Age groups for GAM model
age_grp2 = ifelse(age >= 30 & age < 60, 1, 0),
period.f = as.factor(period))
datComplete <- datComplete %>%
filter(age >= 16 & age <=95) %>%
mutate(age_cohort_five = findInterval(born_adult, c(seq(1910, 2020, by = 5))))  ##cohort groups for rHAPC
#Create subfolders for output
dir.create("plots", showWarnings = FALSE)
dir.create("plots/Appendix", showWarnings = FALSE)
dir.create("tables", showWarnings = FALSE)
###APC-Analysis Diffuse Support
source("02_R_Syntax_diffuse_support_revision.R")
parallel <- fa.parallel(dataEFA_Full, fm = 'minres', fa = 'fa')
fa.parallel(dataEFA_Full, fm = 'minres', fa = 'fa')
##Factor Analysis in Both Regions of Germany, Factor = 1
commonFactor <- fa(dataEFA_Full,nfactors = 1,rotate = "oblimin",fm="minres")
print(commonFactor)
print(commonFactor$loadings)
commonFactorSlice <- dataEFA %>%
arrange(east, period.f) %>%
group_by(east, period.f) %>%
group_map(~ fa(.,nfactors = 1,rotate = "oblimin",fm="minres"))
names(commonFactorSlice) <- dataEFA %>%
arrange(east, period.f) %>%
group_by(east, period.f) %>%
slice(1) %>%
select(east, period.f) %>%
ungroup() %>%
mutate(east = if_else(east == 0, "West", "East")) %>%
mutate(ePeriod = paste(east, period.f, sep = "_")) %>%
pull(ePeriod)
for(i in 1:10){
print(names(commonFactorSlice)[i])
print(commonFactorSlice[[i]]$loadings)
}
#Get all packages with the version used for this analysis
renv::restore()
####Reading the data and loading the packages#####
if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse, haven, mgcv, itsadug, lme4, sjPlot, gridExtra, grid, rlist, texreg, tidymv, psych, GPArotation, rtf, mgcViz, gratia, here)
SYNTAX_DIR <- here::here()
setwd(SYNTAX_DIR)
dat <- haven::read_dta(paste0("data_supportdemocracy_ger.dta"))
####Data Manipulation####
datComplete <- dat %>%
mutate(idea_democracy = round(idea_democracy, 2),
libdem_opposition = round(libdem_opposition, 2),
libdem_freeopinion = round(libdem_freeopinion, 2),
libdem_partyopportunity = round(libdem_partyopportunity, 2),
libdem_criticism = round(libdem_criticism, 2),
libdem_conflict = round(libdem_conflict, 2),
libdem_generalwill = round(libdem_generalwill, 2),
satisfaction_democracy = round(satisfaction_democracy, 2),
period = surveyyear,
birthyear = period - age) %>%
mutate(born_adult = birthyear + 18) %>%
mutate(age_grp = ifelse(age >= 15 & age <20, 1, ifelse(
age >= 20 & age < 30,  2, ifelse(
age >= 30 & age < 40, 3, ifelse(
age >= 40 & age < 50,  4, ifelse(
age >= 50 & age < 60,  5, ifelse(
age >= 60 & age < 70,  6, ifelse(
age >= 70 & age < 80,  7,  8
)
)
)
)
)
)),
age_grp_centered = age_grp - mean(age_grp, na.rm = T),
born_adult_centered = born_adult - mean(born_adult, na.rm = T),
age_grp1 = ifelse(age >= 15 & age < 30, 1,0),     ##Age groups for GAM model
age_grp2 = ifelse(age >= 30 & age < 60, 1, 0),
period.f = as.factor(period))
datComplete <- datComplete %>%
filter(age >= 16 & age <=95) %>%
mutate(age_cohort_five = findInterval(born_adult, c(seq(1910, 2020, by = 5))))  ##cohort groups for rHAPC
#Select Data
dataEFA <- datComplete %>%
select(east, period.f, libdem_freeopinion, libdem_generalwill, libdem_criticism, libdem_conflict, libdem_partyopportunity, libdem_opposition) %>%
drop_na()
##Dataset without East, Period Variables
dataEFA_Full <- dataEFA %>%
select(-c(east, period.f))
# Factor Analysis for full dataset across Germany
## Eigenvalue > 1 only for Factor = 1
## What is reported in the appendix
parallel <- fa.parallel(dataEFA_Full, fm = 'minres', fa = 'fa')
fa.parallel(dataEFA_Full, fm = 'minres', fa = 'fa')
set.seed(1234)
#Select Data
dataEFA <- datComplete %>%
select(east, period.f, libdem_freeopinion, libdem_generalwill, libdem_criticism, libdem_conflict, libdem_partyopportunity, libdem_opposition) %>%
drop_na()
##Dataset without East, Period Variables
dataEFA_Full <- dataEFA %>%
select(-c(east, period.f))
# Factor Analysis for full dataset across Germany
## Eigenvalue > 1 only for Factor = 1
## What is reported in the appendix
parallel <- fa.parallel(dataEFA_Full, fm = 'minres', fa = 'fa')
fa.parallel(dataEFA_Full, fm = 'minres', fa = 'fa')
